package com.weaver.qfengx;

import java.util.Map;
import java.util.Objects;

/**
 * 人员组织相关工具类
 * Created by YeShengtao on 2020/11/11 14:57
 */
public class HrmUtils {

    /**
     * 获取当前部门的一级部门
     */
    public static String topDeptId(String id) {
        Map<String, String> map = DaoUtils.executeQueryToMap("select id, supdepid, departmentname from HrmDepartment where id = ?", id);
        if (Objects.isNull(map)) {
            return null;
        }
        // 递归查询所在一级部门
        while (!StringUtils.equals("0", StringUtils.val(map.get("supdepid")))) {
            map = DaoUtils.executeQueryToMap("select id, supdepid, departmentname from HrmDepartment where id = ?", StringUtils.val(map.get("supdepid")));
            if (Objects.isNull(map)) {
                return null;
            }
        }
        return StringUtils.val(map.get("id"));
    }

}
